/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package myservlet;

import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class AuthFilter implements Filter {

    @Override
    public void destroy() {

    }

    @Override
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
		// TODO Auto-generated method stub
		//通过过滤器进行登录过滤，不是进行合法用户名密码登录的，不可以跳转到下一页面，防止通过路径直接访问网页
		HttpServletRequest requ=(HttpServletRequest)request;
		HttpServletResponse res=(HttpServletResponse)response;
		if(requ.getSession().getAttribute("userSession")!=null){
                           chain.doFilter(request, response);
		}else{
			res.sendRedirect("QAQSorry.jsp");
		}

        }
        
    @Override
    public void init(FilterConfig arg0) throws ServletException {

    }

}


